package
{
	import frameworks.widgets.Result;
	
	import mx.controls.Alert;
	
	public class Util
	{
		public static function ObjectIsEmpty(obj:Object):Boolean{
			for(var key:* in obj){
				return false;
			}
			return true;
		}
		public static function RandRange(min:Number, max:Number):Number {
			var randomNum:Number = Math.floor(Math.random() * (max - min + 1)) + min;
			return randomNum;
		}
		public static function GlobalErrorCallback(vo:Result):void{
			Alert.show(vo.formatErrorMessage(), Language.ErrorTitlePop);
		}
		public static function FormatString(source:String, params:Object, splitter:Array=null):String{
			if(splitter==null){splitter = ["%%","%%"];}
			var re:RegExp = new RegExp("\\"+splitter[0]+"([^\\"+splitter[0]+"\\"+splitter[1]+"]*)\\"+splitter[1],"g");
			if (re.test(source)) { source = FormatStringReplace(re, source, params); }
			return source;
		};
		public static function FormatStringReplace(reg:RegExp, template:String, data:Object):String{
			var fun:Function = function (a:String, b:String):String {
				var r:String = data[b] as String;
				return (r !== null) ? r : a;
			};
			return template.replace(reg, fun);
		}
		
		public function Util()
		{
		}
	}
}